﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Data.SqlClient;

/// <summary>
/// Summary description for DAL_ChildrenClass
/// </summary>
public class DAL_ChildrenClass : clsConnection
{
    DataTable dt = new DataTable();
    clsQueryList clsquery = new clsQueryList();
    public DataTable DAL_ChildrenClass_getAllData()
    {
        try
        {
            dt = ExcuteQuery("SELECT * FROM ChildrenClass");
        }
        catch
        {
        }
        return dt;
    }
    public Boolean DAL_ChildrenClass_addtodel(int id)
    {
        try
        {
            string sql = "delete from ChildrenClass where id=" + id;
            clsquery.addSQL(sql);
        }
        catch
        {
            return false;
        }
        return true;
    }
    public Boolean DAL_ChildrenClass_del()
    {
        try
        {
            clsquery.Execute();
        }
        catch
        {
            return false;
        }
        return true;
    }
    public DataTable DAL_ChildrenClass_getAllByChildrenid(string id)
    {
        try
        {
            dt = ExcuteQuery("SELECT * FROM ChildrenClass WHERE childrenid='" + id + "'");
        }
        catch
        {
        }
        return dt;
    }
    public DataTable DAL_ChildrenClass_getAllByClassid(string cid)
    {
        try
        {
            dt = ExcuteQuery("SELECT * FROM ChildrenClass inner join children on childrenClass.childrenid = children.childrenid WHERE classid='" + cid + "'");
        }
        catch
        {
        }
        return dt;
    }
    //dang ky lop
    public DataTable DAL_ChildrenClass_getDK(string id)
    {
        try
        {
            dt = ExcuteQuery("SELECT * FROM ChildrenClass WHERE childrenid='" + id + "'");
        }
        catch
        {
        }
        return dt;
    }
    public Boolean DAL_ChildrenClass_InsertDK(DTO_ChildrenClass obj)
    {
        try
        {
            string sql = "INSERT INTO ChildrenClass(childrenid, classid) VALUES(@childrenid, @classid)";
            AddParameter(new SqlParameter("@childrenid", obj.Childrenid));
            //AddParameter(new SqlParameter("@classtype", obj.Classtype));
            AddParameter(new SqlParameter("@classid", obj.Classid));
            //AddParameter(new SqlParameter("@status", obj.Status));

            if (ExcuteNonQuery(sql))
            {
                return true;
            }
            else
            {
                return false;
            }

        }
        catch
        {
            return false;
        }
    }
    public Boolean DAL_ChildrenClass_Update(DTO_ChildrenClass obj)
    {
        try
        {
            string sql = "UPDATE ChildrenClass SET height = @height, weight = @weight, healthy = @healthy WHERE id = @id";
            //AddParameter(new SqlParameter("@name", obj.Name));
            AddParameter(new SqlParameter("@height", obj.Height));
            AddParameter(new SqlParameter("@weight", obj.Weight));
            AddParameter(new SqlParameter("@healthy", obj.Healthy));
            AddParameter(new SqlParameter("@id", obj.ID));

            if (ExcuteNonQuery(sql))
            {
                return true;
            }
            else
            {
                return false;
            }

        }
        catch
        {
            return false;
        }
    }
    public DataTable DAL_ChildrenClass_getSearch(string childrenid, string classid)
    {
        try
        {
            dt = ExcuteQuery("SELECT * FROM ChildrenClass WHERE childrenid Like '%" + childrenid + "%' AND classid LIKE N'%" + classid + "%'");
        }
        catch
        {
        }
        return dt;
    }
}